package com.itheima.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.IntFunction;

public class StreamDemo3 {
    public static void main(String[] args) {
       /* void forEach(Consumer action)
        遍历
        long count()
        统计
        toArray()
        收集流中的数据，放到数组中*/
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "张无忌", "张无忌", "赵敏", "周芷若",
                "张翠山");
        list.stream().forEach(s -> System.out.println(s));
        long count = list.stream().count();
        System.out.println(count);

        Object[] arr = list.stream().toArray();
        System.out.println(Arrays.toString(arr));

        String[] arr1 = list.stream().toArray(new IntFunction<String[]>() {
            @Override
            public String[] apply(int value) {
                return new String[value];
            }
        });
        System.out.println(Arrays.toString(arr1));
    }
}
